﻿using Common.Utils;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using Wallpaper.Models.DTOs.Responses;
using Wallpaper.Services.IService;

namespace WallpaperApi.Controllers
{
    [Route("api/permissions")]
    [ApiController]
    public class PermissionController : ControllerBase
    {
        readonly IPermissionService _permissionService;
        readonly ILogger<PermissionController> _logger;

        public PermissionController(IPermissionService permissionService, ILogger<PermissionController> logger)
        {
            _permissionService = permissionService;
            _logger = logger;
        }

        /// <summary>
        /// 获取所有权限树
        /// </summary>
        [HttpGet("tree")]
        public async Task<ApiResponse<List<PermissionTreeResponse>>> GetPermissionTree()
        {
            try
            {
                _logger.LogInformation("获取所有权限");
                List<PermissionTreeResponse> list = await _permissionService.GetPermissionTreeAsync();
                return ApiResponse<List<PermissionTreeResponse>>.Success(list);
            }
            catch(Exception ex) {


                _logger.LogError(ex, "获取所有权限失败");
                throw; 

            }
        }
    }
}
